import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
* @description: 690. 员工的重要性
* @author hewei
* @date 2022/8/11 15:04
* @version 1.0
*/

public class GetImportance {

    public int getImportance(List<Employee> employees, int id) {
        HashMap<Integer, Employee> map = new HashMap<>();
        for (Employee employee : employees) {
            map.put(employee.id, employee);
        }
        Deque<Employee> queue = new LinkedList<>();
        queue.add(map.get(id));
        int ans = 0;
        while (!queue.isEmpty()) {
            Employee poll = queue.poll();
            ans += poll.importance;
            for (Integer subordinate : poll.subordinates) {
                queue.offer(map.get(subordinate));
            }
        }
        return ans;
    }
}

class Employee {
    public int id;
    public int importance;
    public List<Integer> subordinates;
}
